package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.ProvinceEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class ProvinceAdapter extends BaseRecycleAdapter<ProvinceEntity<List<ProvinceEntity>>> {

    private TextView namaView;

    public ProvinceAdapter(Context context, List<ProvinceEntity<List<ProvinceEntity>>> datas) {
        super(context, R.layout.item_province, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final ProvinceEntity<List<ProvinceEntity>> entity) {
        holder.setBinding(BR.viewModel, entity);
        namaView = holder.getItem().findViewById(R.id.name_view);
        String name = entity.getAreaName();
        if (!name.contains("省")) {
            if (name.contains("内蒙古") || name.contains("黑龙江")) {
                name = name.substring(0, 3);
            } else {
                name = name.substring(0, 2);
            }
        } else {
            name = name.substring(0, name.length() - 1);
        }
        namaView.setText(name);
    }

}
